<style>
    #febs-quest xm-select {
        min-height: 30px;
        line-height: 30px;
    }

</style>

<div class="layui-fluid layui-anim febs-anim" id="febs-quest" lay-title="满意度调查表">
    <div class="layui-row layui-col-space8 febs-container">
        <div class="layui-col-md12 layui-col-sm12 layui-col-xs12">
            <div class="layui-card" style="margin: 0 auto;">
                <div class="layui-card-header">床旁交互系统apk上传</div>
                <div class="layui-card-body user-profile-card">

                    <form class="layui-form" action="" lay-filter="bedside-apk-add">
                        <div class="layui-form-item">

                            <div class="layui-inline">
                                <label class="layui-form-label">apk名称：</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="bedapkName" id="bedapkName" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-inline">
                                <label class="layui-form-label">apk版本号：</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="apkCode" id="apkCode" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-inline">
                                <label class="layui-form-label">apk类型：</label>
                                <div class="layui-input-inline">
                                    <select name="apkType" id="apkType">
                                        <option value=""></option>
                                        <option value="0">床旁交互系统</option>
                                        <option value="1">护士站看板</option>
                                        <option value="2">移动护理交互系统</option>
                                    </select>
                                </div>
                            </div>

                            <div class="layui-upload">
                                <button type="button" name="test8" class="layui-btn layui-btn-normal" id="test8">
                                    选择文件
                                </button>
                                <button class="layui-btn layui-btn-normal layui-btn-radius" lay-submit
                                        lay-filter="bedapk-update-submit" id="submit">
                                    <i style="display: none; margin-left: 30px"
                                       class="layui-icon layui-icon-loading layui-icon layui-anim layui-anim-rotate layui-anim-loop"></i>
                                    开始上传
                                </button>

                                <table lay-filter="bedapkTable" lay-data="{id: 'bedapkTable'}"></table>

                            </div>
                        </div>
                    </form>
                </div>
            </div>

            <div class="layui-card" style="margin: 0 auto; margin-top: 20px">
                <div class="layui-card-header">移动护理交互系统apk上传</div>
                <div class="layui-card-body user-profile-card">


                </div>
            </div>

        </div>
    </div>
</div>

<script type="text/html" id="user-option">
    <!--    <a lay-event="detail">-->
    <!--        <i class="layui-icon febs-edit-area febs-green">&#xe7a5;</i></a>-->
    <!--    <a lay-event="edit"><i-->
    <!--            class="layui-icon febs-edit-area febs-blue">&#xe7a4;</i></a>-->
    <a lay-event="del"><i class="layui-icon febs-edit-area febs-red">&#xe7f9;</i></a>
</script>

<script data-th-inline="none" type="text/javascript">
    layui.use(['upload', 'jquery', 'febs', 'form', 'table'], function () {
        let $ = layui.jquery,
            febs = layui.febs,
            table = layui.table,
            form = layui.form,
            $view = $('#febs-quest'),
            upload = layui.upload,
            tableIns
        form.render();


        initBedTable();

        form.on('submit(bedapk-update-submit)', function (data) {
            if (!data.field.bedapkName) {
                febs.alert.warn('请输入apk名称');
                return false;
            }
            if (!data.field.apkCode) {
                febs.alert.warn('请输入apk版本号');
                return false;
            }
            if (!data.field.apkType) {
                febs.alert.warn('请输入apk类型');
                return false;
            }
            uploadInst.upload()

            return false;
        });

        // 上传文件
        var uploadInst = upload.render({
            elem: '#test8'
            , url: ctx + 'web/upload'
            , auto: false
            , accept: "file"
            , data: {
                "apkName": function () {
                    return $('#bedapkName').val();
                },
                "apkCode": function () {
                    return $('#apkCode').val();
                },
                "apkType": function () {
                    return $('#apkType').val();
                }
            }
            , done: function (res) {
                $("#submit").text("上传成功");
                layer.closeAll();
                window.location.reload();
            }
            , before: function (r) {
                let loading = $(this).find('.layui-icon');
                if (loading.is(":visible")) return;
                loading.show();
            }
            , error: function () { //传输失败的回调
                //请求异常回调
                $("#submit").text("上传失败");
            }
        });


        function initBedTable() {
            tableIns = febs.table.init({
                elem: $view.find('table'),
                id: 'questTable',
                url: ctx + 'web/get/listapk',
                method: 'post',
                page: false,
                totalRow: true,
                parseData: function (res) { //res 即为原始返回的数据
                    return {
                        "code": 0, //解析接口状态
                        "msg": "", //解析提示文本
                        data: res.data //解析数据列表
                    };
                },
                cols: [[
                    // {field: 'id', title: 'id',},
                    {field: 'apkName', title: 'apk名称'},
                    {field: 'apkCode', title: 'apk版本号'},
                    {
                        field: 'apkType', title: 'apk类型', templet: function (d) {
                            if (d.apkType === 0) {
                                return "床旁交互系统"
                            } else if (d.apkType === 1) {
                                return "护士站看板"
                            } else {
                                return "移动护理交互系统"
                            }

                        }
                    },
                    {field: 'apkPath', title: 'apk保存的url'},
                    {title: '操作', toolbar: '#user-option', width: 120}
                ]]
            });
        }

        table.on('tool(bedapkTable)', function (obj) {
            let data = obj.data,
                layEvent = obj.event;
            console.log(data)
            if (layEvent === 'del') {
                febs.modal.confirm('删除Apk', '确定删除该Apk？', function () {
                    febs.post(ctx + 'web/delete/apk', {id: data.id}, function () {
                        febs.alert.success('删除Apk成功');
                        layer.closeAll();
                        window.location.reload();
                    });
                });
            }
        });


    })


</script>